package com.ly.learn.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ly.learn.entity.CmsSysPermission;
import com.ly.learn.service.ICmsSysPermissionService;
import com.ly.learn.util.ResultData;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author LY
 * @create 2023/12/21 13:58
 * @Description 权限控制层
 */
@RestController
public class CmsSysPermissionController {

    @Resource
    private ICmsSysPermissionService iCmsSysPermissionService;

    /**
     * 获取所有数据
     * @return
     */
    @GetMapping("/getPermission")
    public ResultData getPermission(){
        List<CmsSysPermission> permissionList = iCmsSysPermissionService.list();
        return new ResultData(permissionList);
    }

    /**
     * 获取带查询条件的数据
     * @return
     */
    @GetMapping("/findPermission")
    public ResultData findPermission(){
        QueryWrapper<CmsSysPermission> wrapper = new QueryWrapper<>();
        wrapper.eq("isActive", true);
        List<CmsSysPermission> permissionList = iCmsSysPermissionService.list(wrapper);
        return new ResultData(permissionList);
    }

    /**
     * 获取树形数据
     * @return
     */
    @GetMapping("/getPermissionTree")
    public ResultData getPermissionTree(){
        List<CmsSysPermission> permissionList = iCmsSysPermissionService.getPermissionTree();
        return new ResultData(permissionList);
    }
}
